﻿
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Authorization;
using KDS.Mes.Mes.ProductModes;
using KDS.Mes.Mes.ProductModes.Dtos;
using KDS.Mes.Web.Models.ProductModes;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Controllers
{
    public class ProductModesController : MesControllerBase
    {

        private readonly IProductModeAppService _productModeAppService;

        public ProductModesController(IProductModeAppService productModeAppService)
        {
            _productModeAppService = productModeAppService;
           
        }

        public  ActionResult Index()
        {
		   var model = new GetProductModeInput {FilterText = Request.QueryString["filterText"]};
            return View(model);
           
        }

        [DontWrapResult]
        public JsonResult GetAllProductModes(int limit, int offset, string sortfiled, string sortway)
        {
            var sort = !string.IsNullOrEmpty(sortfiled) ? string.Format("{0} {1}", sortfiled, sortway) : "";
            var filter = new GetProductModeInput
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
            };
            var pagedTasks = _productModeAppService.GetPagedProductModes(filter);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_Bom_ProductModes_Create, AppPermissions.Pages_Bom_ProductModes_Edit)]
        public async Task<PartialViewResult> CreateOrEditProductModeModal(int? id)
        {
		var input=new NullableIdDto<int>{Id=id};
	 
                 var output=    await _productModeAppService.GetProductModeForEditAsync(input);

				 var viewModel=new CreateOrEditProductModeModalViewModel(output);


            return PartialView("_CreateOrEditProductModeModal",viewModel);
        }
	 
       
    }
}